﻿<UserControl x:Class="Microsoft.Research.ScientificWorkflow.ManagementStudioControls.WorkflowManagerModule.RunningWorkflowsListView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" AutomationProperties.AutomationId="RunningWorkflowsControl"
    xmlns:converters="clr-namespace:Microsoft.Research.ScientificWorkflow.ManagementStudioControls.WorkflowManagerModule"
    xmlns:Controls="clr-namespace:Microsoft.Research.ScientificWorkflow.UIDesigner;assembly=Microsoft.Research.ScientificWorkflow.UIDesigner">
    <UserControl.Resources>
        <ContextMenu x:Key="EmptyContextMenu"/>
        <BooleanToVisibilityConverter x:Key="VisibilityConverter"></BooleanToVisibilityConverter>
        <converters:DateTimeConverter x:Key="DateTimeConverter"></converters:DateTimeConverter>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="25"/>
            <RowDefinition Height="36"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Border CornerRadius="5,5,0,0" Grid.Row="1">
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFFBFBFB" Offset="0"/>
                    <GradientStop Color="#FFF0F0F0" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>
            <Grid>
                <StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
                    <Button Style="{DynamicResource MonitorButton}" Width="26" Command="{Binding Path=ShowMonitorCommand}" CommandParameter="{Binding ElementName=DisplayListView, Path=SelectedItem}"  Height="26" ToolTip="Monitor" Margin="5,0,0,0" AutomationProperties.AutomationId="MonitorButton"/>
                    <Button Style="{DynamicResource ButtonPause}" ToolTip="Pause" Command="{Binding Path=PauseWorkflowCommand}" CommandParameter="{Binding ElementName=DisplayListView, Path=SelectedItem}"   Width="26" Height="26" Margin="5,0,0,0" AutomationProperties.AutomationId="PauseButton"/>
                    <Button Style="{DynamicResource ButtonRefresh}" ToolTip="Resume" Command="{Binding Path=ResumeWorkflowCommand}" CommandParameter="{Binding ElementName=DisplayListView, Path=SelectedItem}"   Width="26" Height="26" Margin="5,0,0,0" AutomationProperties.AutomationId="ResumeButton"/>
                    <Button Style="{DynamicResource ButtonTerminate}" ToolTip="Terminate" Width="26" Height="26" Command="{Binding Path=TerminateWorkflowCommand}" CommandParameter="{Binding ElementName=DisplayListView, Path=SelectedItem}" Margin="5,0,0,0" AutomationProperties.AutomationId="TerminateButton"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                    <Button Style="{DynamicResource refreshButton}" Margin="0,0,10,0" Width="24" Height="24" Command="{Binding Path=RefreshListCommand}" ToolTip="Refresh" AutomationProperties.AutomationId="RefreshRunningWorkflows"></Button>
                </StackPanel>
            </Grid>
        </Border>
       
        <Grid Grid.Row="2" Margin="5,10,5,5" Grid.RowSpan="2">
            <Controls:SortListView SelectionMode="Single" SelectedIndex="{Binding Path=SelectedIndex}" Style="{DynamicResource ListViewStyle1}" ItemsSource="{Binding Path=Items}" ScrollViewer.CanContentScroll="True" x:Name="DisplayListView" IsSynchronizedWithCurrentItem="True" ItemTemplate="{DynamicResource ParentDataTemplate}" Width="Auto" Height="Auto" >
                <Controls:SortListView.ItemContainerStyle>
                    <Style TargetType="{x:Type ListViewItem}">
                        <Setter Property="Template" Value="{DynamicResource ListViewItemControlTemplate1}"/>
                        <Setter Property="ContextMenu" Value="{StaticResource EmptyContextMenu}"/>
                        <EventSetter Event="ContextMenuOpening" Handler="ContextMenu_ContextMenuOpening"></EventSetter>
                        <EventSetter Event="MouseDoubleClick" Handler="ListViewItemDoubleClicked"></EventSetter>
                    </Style>
                </Controls:SortListView.ItemContainerStyle>
                <Controls:SortListView.View>
                    <GridView>
                        <Controls:SortListViewColumn SortByDefault="True" DefaultSortDirection="Ascending" MinimumWidth="130" SortProperty="JobName" Header="Job Name" DisplayMemberBinding="{Binding Path=JobName}" />
                        <Controls:SortListViewColumn MinimumWidth="130" Width="130" SortProperty="WorkflowName" Header="Workflow Name" DisplayMemberBinding="{Binding Path=WorkflowName}" />
                        <Controls:SortListViewColumn MinimumWidth="130" Width="130" SortProperty="NodeName" Header="Node" DisplayMemberBinding="{Binding Path=NodeName}" />
                        <Controls:SortListViewColumn MinimumWidth="110" Width="110" SortProperty="ScheduledBy" Header="Executed By" DisplayMemberBinding="{Binding Path=ScheduledBy}" />
                        <Controls:SortListViewColumn MinimumWidth="130" Width="130" SortProperty="StartTime" Header="Date Executed" DisplayMemberBinding="{Binding Path=StartTime, Converter={StaticResource DateTimeConverter}}"/>
                        <Controls:SortListViewColumn MinimumWidth="200" Header="Details" DisplayMemberBinding="{Binding Path=Description}"/>
                    </GridView>
                </Controls:SortListView.View>
            </Controls:SortListView>
            <Grid Background="White" Visibility="{Binding Converter={StaticResource VisibilityConverter}, Path=EmptyList}" Width="{Binding Path=Width, ElementName=ListviewHost}" Height="{Binding Path=Height, ElementName=ListviewHost}">
                <TextBlock HorizontalAlignment="Center" Foreground="Gray">No Items to be shown</TextBlock>
            </Grid>
        </Grid>
        <Border Margin="0,0,0,0" CornerRadius="5,5,0,0" BorderThickness="0,0,0,1" BorderBrush="#FFFFFFFF">
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFFFFFFF" Offset="0"/>
                    <GradientStop Color="#FFE8E8E8" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>
            <TextBlock Text="{Binding Path=ListViewTitle}" TextWrapping="Wrap" FontSize="14" FontWeight="Normal" Margin="7,2,0,0"/>
		</Border>
    </Grid>
</UserControl>
